package com.py.androidUtils.UI;

import java.util.List;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;

import com.py.androidUtils.UI.adapter.PositionAdapter;
import com.py.androidUtils.UI.model.PositionView;
import com.py.androidUtils.UI.utils.LocationUtils;
import com.py.androidUtils.UI.utils.LocationUtils.LoadLocation;
import com.py.androidUtils.base.BaseListActivity;
import com.py.androidUtils.pulltorefrsh.PullToRefreshBase.Mode;
import com.readyidu.app.R;

/**
 * @说明 所在位置
 * @作者 LY
 * @文件 PositionFragment.java
 * @时间 2015年7月18日 下午4:48:07
 * @版权 Copyright(c) 2015 LY-版权所有
 */
public class PositionActivity extends BaseListActivity<PositionView> {
	private LocationUtils locationUtils;

	@Override
	public void onActivityCreatedCallBack() {
		getTitleActionBar().setTitleBar("所在位置");
		getTitleActionBar().setImgLeft(R.drawable.icon_back, new OnClickListener() {
			@Override
			public void onClick(View v) {
				finishactivity(PositionActivity.this);
			}
		});
		commAdapter = new PositionAdapter(PositionActivity.this);
		locationUtils = new LocationUtils(PositionActivity.this);
		PositionView positionView = new PositionView();
		positionView.setId(1);
		positionView.setTitle("不在显示");
		positionView.setSelect(true);
		commAdapter.addObject(positionView);
	}

	@Override
	public void doInbackgroundCallBack() {
		runOnUiThread(new Runnable() {
			@Override
			public void run() {
				if (page == 0) {
					locationUtils.initLocation();
				} else {
					locationUtils.initPoi();
				}
				locationUtils.setLoadLocation(new LoadLocation() {
					@Override
					public void getPosition(List<PositionView> list) {
						baseAction.update(list);
					}
				});
			}
		});
	}

	@Override
	public void onPreExecuteCallBack() {

	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PositionView> doHandelData(Object object) {
		List<PositionView> list = (List<PositionView>) object;
		return list;
	}

	@Override
	public void onItemClickCallBack(AdapterView<?> parent, View view, int position, long id) {
		for (int i = 0; i < commAdapter.getListData().size(); i++) {
			((PositionView) commAdapter.getListData().get(i)).setSelect(false);
		}
		((PositionView) commAdapter.getListData().get(position)).setSelect(true);
		commAdapter.notifyDataSetChanged();
		Intent intent = getIntent();
		intent.putExtra("name", ((PositionView) commAdapter.getListData().get(position)).getTitle());
		setResult(RESULT_OK, intent);
		finishactivity(PositionActivity.this);
	}

	@Override
	public View getHeadView() {
		return null;
	}

	@Override
	public View getFooterView() {
		return null;
	}

	@Override
	public Mode getListViewMode() {
		return PULL_FROM_END;
	}
}
